package com.jtjrenren.android.taxi.passenger.core.order.date;

import android.content.Intent;

import com.jtjrenren.android.taxi.passenger.R;
import com.jtjrenren.android.taxi.passenger.base.BaseActivity;
import com.library.weidget.wheel.timepicker.TimePickerCustome;
import com.library.utils.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;
import datetime.DateTime;

/**
 * Created by Administrator on 2016/1/20.
 */
public class OrderDateSelectDialogActivity extends BaseActivity {
    public static final String EXTRAS_DATE = "date";

    @BindView(R.id.choose_date_timepicker)
    TimePickerCustome timePicker;

    private String chooseDate; //2016-01-25 12:30:00.754
    private Date sdate;

    @Override
    public int getLayoutId() {
        return R.layout.atydlg_choose_date;
    }

    @Override
    public void init() {

        if (getIntent().hasExtra(EXTRAS_DATE)) {
            String date = getIntent().getStringExtra(EXTRAS_DATE);
            if (!StringUtils.isEmpty(date)) {
                sdate = new Date();
                SimpleDateFormat format = new SimpleDateFormat("yyMMddHHmmss");
                try {
                    sdate = format.parse(date);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }


        timePicker.setTimePickerListener(new TimePickerCustome.TimePickerListener() {
            @Override
            public void onPick(DateTime time) {
                if (time != null)
                    chooseDate = time.toString();
                else
                    chooseDate = "";
            }
        });

        if (sdate != null)
            timePicker.setDate(sdate);

    }

    @OnClick(R.id.choose_date_ok)
    public void clickOk() {
        Intent data = new Intent();
        data.putExtra("date", chooseDate);
        setResult(RESULT_OK, data);
        finish();
    }

    @OnClick(R.id.choose_date_ok)
    public void clickCancle() {
        finish();
    }
}
